import Vue from 'vue'
import router from './router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import echarts from 'echarts'
import 'echarts/theme/macarons'
import 'echarts/theme/shine'
import axios from 'axios'
import qs from 'qs'
import store from './store'
import App from './App.vue'
import 'jquery/dist/jquery'
import 'bootstrap/dist/js/bootstrap'
import  waterfall from 'vue-waterfall2'
import HeaderNavigation from "./components/HeaderNavigation"
import GoodsCard from "./components/GoodsCard"
import UserOrderCard from "./components/UserOrderCard"
import moment from "moment";
Vue.component("Card",GoodsCard);
Vue.component('userOrderCard',UserOrderCard);
Vue.component("navigation",HeaderNavigation);
import PageFoot from "./components/PageFoot"
import OrderAddress from "./components/OrderAddress"
import OrderInfo from "./components/OrderInfo"
import SocialDetail from "./components/SocialDetail"
import GoodsClass from "./views/frontstage/GoodsClass"
Vue.component('orderInfo',OrderInfo);
Vue.component('orderAddress',OrderAddress);
Vue.component("foot",PageFoot);
import { library } from '@fortawesome/fontawesome-svg-core'
import { fas } from '@fortawesome/free-solid-svg-icons'
import { far } from '@fortawesome/free-regular-svg-icons'
import { fab } from '@fortawesome/free-brands-svg-icons'
import { FontAwesomeIcon, FontAwesomeLayers, FontAwesomeLayersText } from '@fortawesome/vue-fontawesome'
import el from "element-ui/src/locale/lang/el";
library.add(fas, far, fab);
Vue.component('font-awesome-icon', FontAwesomeIcon);
Vue.component('font-awesome-layers', FontAwesomeLayers);
Vue.component('font-awesome-layers-text', FontAwesomeLayersText);

Vue.prototype.$moment = moment;
Vue.prototype.$echarts=echarts;
Vue.prototype.$axios=axios;

axios.defaults.baseURL='/api';
axios.defaults.headers.post['Content-Type']='multipart/form-data;charset=utf-8';
Vue.config.productionTip = false;

Vue.use(ElementUI);
Vue.use(waterfall);

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app');

router.beforeEach((to, from, next) => {
  document.body.scrollTop = 0;
  document.documentElement.scrollTop = 0;
  window.pageYOffset = 0;
  if(to.meta.needLogin){
    console.log('切换验证');
    if (sessionStorage.getItem('token')){
      next();
    }else {
      next({
          name:'Login',
          query:{redirect:to.fullPath}
      })
    }
  }else {
    next()
  }
});
